package jk.zmn.socket.tcp.demo02;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @author 张梦楠
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018/5/3118:45
 * @blog www.itzmn.com
 *
 * 客户端
 */
public class ClientDemo2 {
     public static void main(String[] args) throws Exception{

         Socket socket = new Socket("localhost", 9999);

         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
         DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
         DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());

         while (true) {
             dataOutputStream.writeUTF(bufferedReader.readLine());
             dataOutputStream.flush();

             //得到服务端的数据
             String s = dataInputStream.readUTF();
             System.out.println(s);
         }
     }
}
